package hc.bre

import java.sql.*
import org.springframework.jdbc.datasource.*

public class DBTest {
	static DriverManagerDataSource dataSource;
	static  public DriverManagerDataSource initIfNone() {

		if(dataSource) return dataSource;

		DriverManagerDataSource ds
		ds = new DriverManagerDataSource();
		ds.setDriverClassName("org.h2.Driver");
		ds.setUrl("jdbc:h2:mem:testdb;MODE=MYSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
		ds.setUsername("root");
		ds.setPassword("root");

		String dataSql = DBTest.getResource("/test/DBTest.data.sql" ).toURI().toString().substring(6);
		Statement st = ds.getConnection().createStatement();
		st.execute( "runscript from '" + dataSql + "'");
		st.close();

		dataSource =ds;
	}
}
